Imports System.ComponentModel

<Description("Bazova trida pro wrapper tridy kolekci.")> _
Public MustInherit Class CollectionWrapperBase
	Inherits ChildObjectWrapperBase

	<Description("Konstruktor.")> _
	Protected Sub New(<Description("Nativni (COM+) objekt.")> ByVal nativeCollection As Object, ByVal rootObject As RootObjectWrapperBase)
		MyBase.New(nativeCollection, rootObject)
	End Sub

    <Description("Vrati wrapper objekt pro nativni (COM+) objekt.")> _
    Protected MustOverride Function WrapItem(<Description("Nativni (COM+) objekt.")> ByVal nativeItem As Object) As IWrapper

	<Description("Upravi hodnotu indexu podle nastaveni v singelton objektu tridy WrapperSettings.")> _
	Friend Shared Sub CorrectIndex(<Description("Index polozky v kolekci.")> ByRef index As Integer)
		WrapperSettings.[Default].CorrectCollectionIndex(index)
	End Sub

    <Description("Pocet zaznamu.")> _
    Public ReadOnly Property Count() As Integer
        Get
            Return Me.WrappedObject.Count
        End Get
    End Property

    <Description("Poskytuje pristup k polozkam pres indexer.")> _
    Default Public ReadOnly Property Item(ByVal index As Integer) As IWrapper
        Get
			CorrectIndex(index)
            Dim rslt As Object = Me.WrappedObject.Item(index)
			Dim wrappedObject As IWrapper = WrapItem(rslt)
			Return wrappedObject
        End Get
    End Property
End Class

Public MustInherit Class CollectionWrapperBase(Of T As IWrapper)
	Inherits CollectionWrapperBase

	Protected Sub New(ByVal nativeCollection As Object, ByVal rootObject As RootObjectWrapperBase)
		MyBase.New(nativeCollection, rootObject)
	End Sub

	Default Public Shadows ReadOnly Property Item(ByVal index As Integer) As T
		Get
			Dim tmpRslt As IWrapper = MyBase.Item(index)
			Dim rslt As T = tmpRslt
			Return rslt
		End Get
	End Property
End Class
